package com.viettel.core.dao.report;

import java.util.ArrayList;
import java.util.List;

import com.viettel.core.entities.report.SmsServiceGroup;
import com.viettel.core.exceptions.DataAccessException;
import com.viettel.core.repo.IRepository;

/**
 * Mo ta muc dich cua lop (interface)
 * 
 * @author: HUYNHDC
 * @version: 1.0
 * @since: 16/07/2014 - 10:50:59
 */
public class SmsServiceGroupDAOImpl implements SmsServiceGroupDAO {

	private IRepository repo;

	public void setRepo(IRepository repo) {
		this.repo = repo;
	}

	@Override
	public SmsServiceGroup getSmsServiceGroupById(Integer id)
			throws DataAccessException {
		return repo.getEntityById(SmsServiceGroup.class, id);
	}

	@Override
	public SmsServiceGroup createSmsServiceGroup(SmsServiceGroup smsServiceGroup)
			throws DataAccessException {
		if (smsServiceGroup == null) {
			throw new IllegalArgumentException("smssendlog");
		}
		repo.create(smsServiceGroup);
		return repo.getEntityById(SmsServiceGroup.class,
				smsServiceGroup.getId());
	}

	@Override
	public void updateSmsServiceGroup(SmsServiceGroup smsServiceGroup)
			throws DataAccessException {
		if (smsServiceGroup == null) {
			throw new IllegalArgumentException("smssendlog");
		}
		repo.update(smsServiceGroup);
	}

	@Override
	public void deleteSmsServiceGroup(SmsServiceGroup smsServiceGroup)
			throws DataAccessException {
		if (smsServiceGroup == null) {
			throw new IllegalArgumentException("smssendlog");
		}
		repo.delete(smsServiceGroup);
	}

	@Override
	public List<SmsServiceGroup> getAllSmsServiceGroup()
			throws DataAccessException {
		List<Object> params = new ArrayList<Object>();
		String sql = "SELECT * FROM SMS_SERVICE_GROUP ORDER BY LOWER(name) ";
		return repo.getListBySQL(SmsServiceGroup.class, sql, params);
	}
}
